package com.itheima.d01_file_methods;

import java.io.File;
import java.io.IOError;
import java.io.IOException;

public class Test01 {
    public static void searchFile(File dir, String fileName) throws IOError, IOException {
        if (dir == null || !dir.exists() || !dir.isDirectory()) {
            return;
        }
        //1.
        File[] files = dir.listFiles();

        if (files != null && files.length > 0) {
            for (File file : files) {
                //2.1
                if (file.isFile()) {
                    System.out.println("判断文件：" + file.getName());
                    //
                    if (file.getName().equals(fileName)) {
                        System.out.println("找到文件,文件路径：" + file.getAbsolutePath());
                        Runtime runtime = Runtime.getRuntime();
                        runtime.exec(file.getAbsolutePath());
                    }
                } else {
                    System.out.println("递归文件夹：" + file.getName());
                    //
                    //
                    searchFile(file, fileName);
                }
            }
        }
    }
    public static void main(String[] args) throws IOException {
        searchFile(new File("D:\\"), "uu_launcher.exe");
    }

}


